<template>
  <div class="container">
    <div class="import">
      <el-upload
        class="upload-demo"
        drag
        action="#"
        :limit="1"
        :auto-upload="false"
        :on-change="onChange"
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或<em @click="upload">点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">
          只能上传单文件，且不超过100MB
        </div>
      </el-upload>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      file: "",
    };
  },
  methods: {
    // 当文件列表发生改变时，获取文件内容
    onChange(file, fileList) {
      this.file = fileList[0].raw;
    },
    upload() {
      if (this.file.length == 0) return;
      let formData = new FormData();
      formData.append("multipartFile", this.file);
      formData.append("url", "/user/add/file");
      this.$store.dispatch("request/postF", formData).then(() => {
        this.$message.success("名单导入成功!!");
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.container {
  height: 100%;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
}
.import {
  height: 100%;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>